<?php

namespace app\index\controller;

use app\admin\model\Order;
use app\common\controller\Frontend;
use app\common\model\OrderInfo;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        return $this->redirect('HRjSYNCiaU.php/index/login');
//        return $this->view->fetch();
    }

    public function pdf(){
        $order_id = input('id',65);



        $orderModel = new \app\common\model\Order();
        $orderInfo = $orderModel->where('id', $order_id)->find();
        $orderInfoModel = new OrderInfo();
        $category = new \app\common\model\Category();
//        $orderInfo['infos'] = $orderInfoModel->where('order_id', $order_id)->column('first_cat_id');
//        dd($orderInfoModel->where('order_id', $order_id)->column('first_cat_id'));
//        $orderInfo['infos'] = $category->whereIn('id', $orderInfoModel->where('order_id', $order_id)->column('first_cat_id'))->where('pid',0)->field('id,name,image,type,flag')->select()->each(function ($item) {
//            $item['image'] = get_app_image_url($item['image']);
//        });
        $categoryList = $category->whereIn('id', $orderInfoModel->where('order_id', $order_id)->column('first_cat_id'))->field('id,name,image,type,flag,description')->select();
        foreach ($categoryList as $k => &$v) {
            $v['image'] = get_app_image_url($v['image']);
            $v['child'] = $orderInfoModel->where('order_id', $order_id)->where('first_cat_id', $v['id'])->select();
        }
//        $orderInfo['category'] = $categoryList;
//        $orderInfo['infos'] = $categoryList;
//        dd(toArray($orderInfo));
//        var_dump($orderInfo);
        $this->view->assign("info", $orderInfo);
        $this->view->assign("list", $categoryList);
        return $this->view->fetch();
    }


}
